package com.frinder.official.akka.actors;

import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import com.frinder.official.spring.SpringExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * Created by frinder on 2017/9/12.
 */
@Component
@Scope("prototype")
public class FirstActor extends AbstractActor {

    @Autowired
    private SpringExtension springExtension;

    /**
     * 注：在 Actor内部“创建”其它 Actor，推荐使用 getContext().actorOf(..)的方式，这样才会存在层级关系
     */
    final ActorRef child = getContext().actorOf(springExtension.props("myActor"), "my-actor");

    @Override
    public Receive createReceive() {
        return receiveBuilder()
                .matchAny(x -> getSender().tell(x, getSelf()))
                .build();
    }

}
